﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SEVN.Web.Framework.Modules.News
{
    public partial class CateNews0202 : System.Web.UI.UserControl
    {
        WebFrameDataContext web = new WebFrameDataContext();
        protected void Page_Load(object sender, EventArgs e)
        {
            rptcatenew.DataSource = web.Categories.Where(x => x.IsFontPage == true);
            rptcatenew.DataBind();

        }

        protected void rptcatenew_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            HiddenField hf = (HiddenField)e.Item.FindControl("hf");
            DataList dl = (DataList)e.Item.FindControl("DataList1");
            if (hf != null && dl != null)
            {
                var list = from x in web.Newsletters
                           from y in web.Categories
                           orderby x.CreateDate descending
                           where x.CategoryID.ToString() == hf.Value && x.CategoryID == y.CategoryID
                           select new
                           {
                               x.NewsID,
                               x.Title,
                               Detail = x.Detail.Substring(0, 66),
                               x.Image,
                               x.ImageDefault,
                               x.CreateDate,
                               x.CategoryID
                           };

                dl.DataSource = list.Take(4);
                dl.DataBind();
            }
        }
    }
}